package gh625simpleviewer;

import java.io.File;
import java.util.Properties;

public class Main {

    public static void main(String[] args) {
        // Initialisation
        Vars.OptsFileName = System.getProperty("user.home") + "/.gh625simpleviewer/Options.xml";
        File optsdir = new File(System.getProperty("user.home") + "/.gh625simpleviewer");
        if (!optsdir.exists()) {
            optsdir.mkdirs();
        }
        // End of initialisation

        Vars.LoadOptions();
        if (!Vars.opts.containsKey("ComPortName")) {
            if (System.getProperty("os.name").contains("Windows")) {
                Vars.opts.setProperty("ComPortName", "COM3");
            } else {
                Vars.opts.setProperty("ComPortName", "/dev/ttyUSB0");
            }
            Vars.SaveOptions();
        }
        if (!Vars.opts.containsKey("UseProxy")) {
            Vars.opts.setProperty("UseProxy", "False");
            Vars.SaveOptions();
        }
        if (!Vars.opts.containsKey("ProxyHost")) {
            Vars.opts.setProperty("ProxyHost", "");
            Vars.SaveOptions();
        }
        if (!Vars.opts.containsKey("ProxyPort")) {
            Vars.opts.setProperty("ProxyPort", "");
            Vars.SaveOptions();
        }

        if (Vars.opts.getProperty("UseProxy").equals("True")) {
            Properties prop = System.getProperties();
            prop.put("http.proxyHost", Vars.opts.getProperty("ProxyHost"));
            prop.put("http.proxyPort", Vars.opts.getProperty("ProxyPort"));
            System.setProperties(prop);
        }

        MainFrame frm = new MainFrame();
        frm.setLocationRelativeTo(null);
        frm.setVisible(true);
    }
}
